//
//  CPTableController.m
//  News
//
//  Created by chen on 15/3/26.
//  Copyright (c) 2015年 chen. All rights reserved.
//

#import "CPTableController.h"
#import "CPCellModal.h"

NSString *const CPModalNotification = @"CPModalNotification";
NSString *const CPModalKey = @"CPModalKey";
@interface CPTableController ()

@property (nonatomic, strong) NSArray *cellTotalModals;

@end

@implementation CPTableController

- (NSArray *)cellTotalModals{
    
     if (_cellTotalModals == nil)
     {
         _cellTotalModals = [CPCellModal CellTotalModals];
         
     }
    return  _cellTotalModals;
    
}

static  NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseIdentifier];
    
}


#pragma  mark - tableView 的数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return  self.cellTotalModals.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    
    CPCellModal *modal  = self.cellTotalModals[indexPath.row];
    cell.textLabel.text = modal.title;
    return cell;

}

#pragma  mark - tableView 的代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CPCellModal *modal = self.cellTotalModals[indexPath.row];
    NSDictionary *dic = @{CPModalKey:modal};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:CPModalNotification object:nil userInfo:dic];
    
    CGFloat width = self.tableView.frame.size.width;
    CGFloat height = self.tableView.frame.size.height;
    [UIView animateWithDuration:0.5f animations:^{
        
        [self.tableView setFrame:CGRectMake(-width, 0.0f, width, height)];

    }];
}



@end
